<template>
	<view>
		<ttBar :title="storeName?storeName:'课程中心'"  leftIcon="icon-back"></ttBar>
		<scroll-view scroll-y="true" :style="{'height':top+'px'}" @scrolltolower="getData">
			<goodList v-if="listData.length>0" :goodData="listData"></goodList>
			<emptyBox v-if="listData.length<1" :isLoding="loding"></emptyBox>
		</scroll-view>
		
	</view>
</template>

<script>
	import ttBar from "@/components/ttBar/ttBar.vue";
	import goodList from "@/components/goodList/goodList.vue";
	import emptyBox from "@/components/emptyBox/emptyBox.vue";
	import {
		mapState,
		mapGetters,
		mapMutation,
		mapActions
	} from "vuex";
	export default {
		computed: {
			...mapState({
				locationCity:state=>state.map.locationCity,
				selectCity:state=>state.map.selectCity,
				roads: state => state.map.roads
			})
		},
		components: {
			ttBar,
			goodList,
			emptyBox,
		},
		data() {
			return {
				top: uni.getSystemInfoSync().screenHeight-uni.getSystemInfoSync().statusBarHeight-uni.upx2px(90),
				hasNext:true,
				storeId:0,
				storeName:'',
				listData:[],
				rmdFilter: {
					page_no: 1,
					page_size: 10,
					areaId: 0
				},
				loding:true
			};
		},
		methods:{
			getData(){
				this.rmdFilter.areaId = this.selectCity.cityCode;
				if(this.hasNext){
					this.loding=true;
					this.rmdFilter.storeId=this.storeId;
					this.$store.dispatch("apiSearchGood",this.rmdFilter)
					.then(res=>{
						this.listData=this.listData.concat(res.data.data.items);
						this.rmdFilter.page_no = res.data.data.nextPage;
						this.hasNext=res.data.data.hasNext;
						this.loding=false;
					})
					
				}else{
					uni.showToast({
						title: '没有更多的数据了',
						icon: 'none'
					});
				}
				
			}
		},
		onLoad(cfm) {
			this.storeName=cfm.sname
			this.storeId=cfm.sid;
			this.getData()
		},
		// 下拉刷新
		onPullDownRefresh() {
			setTimeout(() => {
				this.listData=[];
				this.rmdFilter.page_no=1;
				this.hasNext=true;
				this.getData()
				uni.stopPullDownRefresh();
			}, 1500)
		}
	}
</script>

<style lang="less">
page{
	background-color: #f6f6f6;
}
</style>
